package baseTest;

public class longestCommonPrefix {
    public static void main(String[] args) {
        String[] strs = {"ab","a"};
        System.out.println(process(strs));
    }
    public static String process(String[] strs){
        int length = strs[0].length();
        int n = 0;
        boolean flag = true;
        for (int i = 0; i < length && flag; i++) {
            char cur = strs[0].charAt(i);
            for (int j = 1; j < strs.length; j++) {
                if (i < strs[j].length() && cur == strs[j].charAt(i)){
                    continue;
                }
                flag = false;
                break;
            }
            if (flag)
            n++;
        }
        return n>0? strs[0].substring(0,n): "";
    }
}
